#include "usb/disk.h"


namespace iecas_ns
{
    shared_ptr<CDisk> CDisk::sm_intancePtr = nullptr;

    CDisk::CDisk()
    {
        m_commonPtr = shared_ptr<CCommon>(CCommon::getInstance());
        m_srcDev = "";
        pwd_shell = "sh $PWD/";
    }

	shared_ptr<CDisk> CDisk::getInstance()
	{
		if(sm_intancePtr == nullptr)
		{
			sm_intancePtr = shared_ptr<CDisk>(new CDisk());
		}
		return sm_intancePtr;
	}

    bool CDisk::init(string srcDev)
    {
        string tmp_back, cmd_shell;

        m_commonPtr->addDev(srcDev);

        cmd_shell = pwd_shell + INIT_DISK_SH_FILE_NAME + " " + srcDev;

        cout << "cpp call linux shell: " << cmd_shell << endl;
        PLOGD << "cpp call linux shell: " << cmd_shell;
        sleep(1);
        system(cmd_shell.c_str());

        return true;
    }

    void CDisk::start(void)
    {
        thread tempThread(&CDisk::loop, this);
        tempThread.detach();
    }

    void CDisk::loop(void)
    {

    }

    bool CDisk::deinit(string srcDev)
    {
        m_commonPtr->delDev(srcDev);

        return true;
    }
}
